﻿/***********************************************************************
 * Module:  CPFRegisterService.cpp
 * Author:  ZHANGHASI
 * Modified: 2020年12月7日 下午 3:49:55
 * Purpose: Implementation of the class CPFRegisterService
 ***********************************************************************/


#include "CPFRegisterService.h"


// 注册服务线程锁
std::mutex g_registerServiceMutex;

CPFRegisterService::CPFRegisterService()
{

}

CPFRegisterService::~CPFRegisterService()
{

}
////////////////////////////////////////////////////////////////////////
// Name:       CPFRegisterService::instance()
// Purpose:    Implementation of CPFRegisterService::instance()
// Return:     CPFRegisterService*
////////////////////////////////////////////////////////////////////////

CPFRegisterService* CPFRegisterService::instance(void)
{
    const std::lock_guard<std::mutex> lock(g_registerServiceMutex);
    static CPFRegisterService* pService = nullptr;
    if (nullptr == pService)
    {
        pService = new CPFRegisterService();
    }
    return pService;
}

////////////////////////////////////////////////////////////////////////
// Name:       CPFRegisterService::registerObject(std::string name, void* object)
// Purpose:    Implementation of CPFRegisterService::registerObject()
// Parameters:
// - name
// - object
// Return:     void
////////////////////////////////////////////////////////////////////////

void CPFRegisterService::registerObject(std::string name, CPFActivator* object)
{
    hash_map<std::string, void*>::iterator iterResult = m_hashService.find(name);

    if (iterResult == m_hashService.end())
    {
        m_hashService.insert(std::make_pair(name, object));
    }
}

////////////////////////////////////////////////////////////////////////
// Name:       CPFRegisterService::unregisterObject(std::string name)
// Purpose:    Implementation of CPFRegisterService::unregisterObject()
// Parameters:
// - name
// Return:     void
////////////////////////////////////////////////////////////////////////

void CPFRegisterService::unregisterObject(std::string name)
{
    hash_map<std::string, void*>::iterator iterResult = m_hashService.find(name);

    if (iterResult != m_hashService.end())
    {
        m_hashService.erase(iterResult);
    }
}


